import { ref } from 'vue'
import { getSystemLog, getLoginLog, getSysLogOperateContent } from '../../../api/basic'
import { GetLogListParam, GetSysListParam } from './types'

// 获取系统操作日志加载状态
const getSystemLogLoading = ref(false)

// 获取登录日志加载状态
const getLoginLogLoading = ref(false)

// 获取操作日志内容加载状态
const getOperateLogContentLoading = ref(false)

// 系统操作日志列表
const systemLogList = ref(null)

// 登录日志列表
const loginLogList = ref(null)

// 日志操作内容
const logOperateContent = ref({
  param: '',
  content: '',
})

// 系统操作日志列表分页数据
const systemLogPagination = ref({
  total: 0,
  limit: 0,
  currentPage: 0,
})

// 登录日志列表分页数据
const loginLogPagination = ref({
  total: 0,
  limit: 0,
  currentPage: 0,
})

// 获取系统操作日志方法
const getSystemLogList = async (data: GetSysListParam) => {
  getSystemLogLoading.value = true
  const res = await getSystemLog(data)
  systemLogList.value = res.data.data.rows
  systemLogPagination.value.total = Number(res.data.data.total)
  systemLogPagination.value.limit = Number(res.data.data.limit)
  systemLogPagination.value.currentPage = Number(res.data.data.currentPage)
  getSystemLogLoading.value = false
}

// 获取登录日志方法
const getLoginLogList = async (data: GetLogListParam) => {
  getLoginLogLoading.value = true
  const res = await getLoginLog(data)
  loginLogList.value = res.data.data.rows
  loginLogPagination.value.total = Number(res.data.data.total)
  loginLogPagination.value.limit = Number(res.data.data.limit)
  loginLogPagination.value.currentPage = Number(res.data.data.currentPage)
  getLoginLogLoading.value = false
}

// 获取日志操作内容方法
const getLogOperateContent = async (id: string) => {
  getOperateLogContentLoading.value = true
  const res = await getSysLogOperateContent(id)
  logOperateContent.value = res.data.data.row
  getOperateLogContentLoading.value = false
}

export default {
  loginLogList,
  systemLogList,
  logOperateContent,
  loginLogPagination,
  systemLogPagination,
  getLoginLogLoading,
  getSystemLogLoading,
  getOperateLogContentLoading,
  getLoginLogList,
  getSystemLogList,
  getLogOperateContent,
}
